//
//  ShoppingRow.m
//  mbstore
//
//  Created by huangyi on 14-3-14.
//  Copyright (c) 2014年 huangyi. All rights reserved.
//

#import "ShoppingRow.h"
#import "AppUI.h"

@implementation ShoppingItem

-(void)setSkuId:(NSString *)skuId{
    _skuId=skuId;
      #warning 调用数据库
    NSDictionary *sku=[AppUI getProductDict:skuId];
    self.photo=sku[@"main_photo"];
    self.color=sku[@"color_name"];
    self.size=sku[@"size_name"];
    self.itemId=sku[@"item_id"];
    self.itemName=sku[@"name"];
    self.price=sku[@"price"];
}

@end

@implementation ShoppingRow

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

-(void)prepareForReuse{
    self.imageView.image=nil;
    self.descriptionText.text=nil;
    self.colorSizeText.text=nil;
    self.quantityText.text=nil;
    self.priceText.text=nil;
    self.priceText.attributedText=nil;
    self.finalPriceText.text=nil;
    self.discountText.text=nil;
    self.checkmarkView.image=nil;
}

-(void)setItem:(ShoppingItem*)item{
    NSString *price=[NSString stringWithFormat:@"¥%@",item.price];
    NSMutableAttributedString *attrprice=[[NSMutableAttributedString alloc] initWithString:price attributes:nil];
    if ([item.finalPrice floatValue])
        [attrprice addAttribute:NSStrikethroughStyleAttributeName value:@1 range:NSMakeRange(0, attrprice.length)];
    
    self.priceText.attributedText=attrprice;
    
    self.descriptionText.text=[NSString stringWithFormat:@"%@（商品编号：%@）",item.itemName,item.itemId];
    self.colorSizeText.text=[NSString stringWithFormat:@"%@ | %@",item.color,item.size];
    self.quantityText.text=[NSString stringWithFormat:@"数量：%@",@(item.count)];
    if ([item.finalPrice floatValue]) {
        self.finalPriceText.text=[NSString stringWithFormat:@"¥%@",item.finalPrice];
    }
    if (item.discount) {
        self.discountText.text=[NSString stringWithFormat:@"%@",item.discount];
    }
    NSString *image =item.photo;
    image = [image stringByDeletingPathExtension];
    image = [NSString stringWithFormat:@"%@--w_100_h_100.jpg",image];
    NSString *imageURL=[AppUI getImageURL:image];
    [self.imageView setImageURL:imageURL];
}
-(void)setCheckmark:(BOOL)checkmark{
    if (checkmark) {
        self.checkmarkView.image=[UIImage imageNamed:@"media.bundle/checkmark.png"];
    }else{
        self.checkmarkView.image=nil;
    }
}

@end
